<?php
/*========================================= JooSam =========================================/
/																							/
/	Extention:		JooSam																	/
/	Created by:		ScriptPlanet.eu															/
/	Site:			http://www.scriptplanet.eu												/
/	Email:			support@scriptplanet.eu													/
/	Support:		http://www.scriptplanet.eu/support										/
/	Copyright:		2011 (c) ScriptPlanet.eu												/
/	License:		CC BY-NC-ND 3.0 ~ http://creativecommons.org/licenses/by-nc-nd/3.0/		/
/	File Version:	0001																	/
/																							/
/========================================== JooSam ========================================*/

// Joomla security
defined('_JEXEC') or die;
 
## Import Joomla Data
jimport('joomla.application.component.controllerform');
 
## Settings Controller
class JooSamControllerSetting extends JControllerForm{
	protected $text_prefix = 'Setting';
	
	## Save button
	public function save($key = null, $urlVar = null){
	
		$this->sqlupdate('1');
		$this->setMessage(JText::_('COM_JOOSAM_SETTING_SAVED'));
		$this->setRedirect(JRoute::_('index.php?option=com_joosam&view=settings', false));
	}

	## Update settings
	protected function sqlupdate($value){
		
		$data = JRequest::getVar('jform', array(), 'post', 'array');
		$pass = $data['password'];
		$db =& JFactory::getDBO();
		if (empty($data['password'])){
		$query = "
			UPDATE ".$db->nameQuote('#__joosam_settings')."
			SET ".$db->nameQuote('sqlip')." = ".$db->quote($data['sqlip']).",
				".$db->nameQuote('sqlport')." = ".$db->quote($data['sqlport']).",
				".$db->nameQuote('sqluser')." = ".$db->quote($data['sqluser']).",
				".$db->nameQuote('sqldb')." = ".$db->quote($data['sqldb']).",
				".$db->nameQuote('imgtype')." = ".$db->quote($data['imgtype']).",
				".$db->nameQuote('imgwidth')." = ".$db->quote($data['imgwidth']).",
				".$db->nameQuote('imgheight')." = ".$db->quote($data['imgheight']).",
				".$db->nameQuote('imglastfmkey')." = ".$db->quote($data['imglastfmkey']).",
				".$db->nameQuote('samsrvip')." = ".$db->quote($data['samsrvip']).",
				".$db->nameQuote('samsrvport')." = ".$db->quote($data['samsrvport']).",
				".$db->nameQuote('samsrvtzone')." = ".$db->quote($data['samsrvtzone'])."
			WHERE ".$db->nameQuote('id')." = ".$db->quote($value).";
		";
		}
		else{
			$passql = JoosamHelper::jscrypt('encode',$pass);
			$query = "
				UPDATE ".$db->nameQuote('#__joosam_settings')."
				SET ".$db->nameQuote('sqlip')." = ".$db->quote($data['sqlip']).",
					".$db->nameQuote('sqlport')." = ".$db->quote($data['sqlport']).",
					".$db->nameQuote('sqluser')." = ".$db->quote($data['sqluser']).",
					".$db->nameQuote('password')." = ".$db->quote($passql).",
					".$db->nameQuote('sqldb')." = ".$db->quote($data['sqldb']).",
					".$db->nameQuote('imgtype')." = ".$db->quote($data['imgtype']).",
					".$db->nameQuote('imgwidth')." = ".$db->quote($data['imgwidth']).",
					".$db->nameQuote('imgheight')." = ".$db->quote($data['imgheight']).",
					".$db->nameQuote('imglastfmkey')." = ".$db->quote($data['imglastfmkey']).",
					".$db->nameQuote('samsrvip')." = ".$db->quote($data['samsrvip']).",
					".$db->nameQuote('samsrvport')." = ".$db->quote($data['samsrvport']).",
					".$db->nameQuote('samsrvtzone')." = ".$db->quote($data['samsrvtzone'])."
				WHERE ".$db->nameQuote('id')." = ".$db->quote($value).";
		";
		}
		$db->setQuery($query);
		$db->query();
		return true;
	}
}
?>